<?php
class user_groupModel extends baseModel{
    protected $table = 'user_group';

    //会员组列表
    public function group_list() {
        return $this->select('','','gid asc');
    }

    //会员组信息
    public function info($gid) {
        return $this->find('gid='.$gid);
    }

    //添加会员组
    public function add($data)
    {
        $data['base_purview']=serialize($data['base_purview']);
        $data['menu_purview']=serialize($data['menu_purview']);
        return $this->insert($data);

    }
    //编辑会员组
    public function edit($data)
    {
        $condition['gid']=intval($data['gid']);
        $data['base_purview']=serialize($data['base_purview']);
        $data['menu_purview']=serialize($data['menu_purview']);
        return $this->update($condition,$data); 
        
    }
    //删除会员组
    public function del($gid)
    {
        //删除关联
        return $this->delete('gid='.intval($gid)); 
    }

    //获取功能权限
    public function get_base_purview(){
        return ApiHook('hook_purview_user');
    }

    //获取菜单权限
    public function get_menu_purview(){
        $base=ApiHook('hook_user_menu_base');
        $manage=ApiHook('hook_user_menu_manage');
        $info=ApiHook('hook_user_menu_info');
        $list= array(
            '基本菜单'=>$base,
            '信息菜单'=>$manage,
            '资料菜单'=>$info,
        );
        $newlist=array();
        foreach ($list as $key => $value) {
            $menulist=array();
            if(!empty($value)){
                foreach ($value as $val) {
                    $menulist=array_merge((array)$val,(array)$menulist);
                }
            }
            $newlist[$key]=$menulist;
        }
        return $newlist;
    }

	
}